//手动引入封装的axios  network
import network from '../network/index'

//相当于index.js里面的一个小组件（模块）
const goodModule = {
    state: {
        goods: [],
        gooddetail: {}
    },
    mutations: {
        getGood(state, items) {
            state.goods = items;
        },
        getGoodDetail(state, items) {
            state.gooddetail = items;
        },
    },
    actions: {
        getGood(context) {
            //调用getlist
            network.getGoodlist({

            })
                .then(res => {
                    window.console.log(res.data.data);
                    // this.barginlist = res.data.data.goodsMap;
                    // commit('需要触发的Mutation函数')
                    context.commit('getGood', res.data.data)
                })
                .catch(error => {
                    window.console.log(error);
                });
        },
        getGoodDetail(context,id) {
            //调用getlist
            network.getGooddetail({
               id:id
            })
                .then(res => {
                    
                    window.console.log(res.data.data);
                    // this.barginlist = res.data.data.goodsMap;
                    // commit('需要触发的Mutation函数')
                    context.commit('getGoodDetail', res.data.data)
                })
                .catch(error => {
                    window.console.log(error);
                });
        },

    },
    modules: {

    }
}

//抛出module
export default goodModule;
